package com.winqai.web.aspect;


import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.util.Date;

@Aspect
@Component
public class TimeAspect {

    //声明 一个切入点 speingframework doc 11.1.2
    //@Around("execution(* com.winqai.web.controller.UserController.*(..))")
    public Object handlerControllerMethod(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("time aspect start ");

        //获得调用方法参数
        Object[] args = pjp.getArgs();
        for(Object arg:args){
            System.out.println("method arg ："+arg);
        }
        long start = new Date().getTime();

        //获得调用方法返回值
        Object object = pjp.proceed();
        System.out.println("time aspect 耗时:"+(new Date().getTime() - start));
        System.out.println("time aspect end");

        return object;
    }

}
